package com.lehoon.tomato.controller;


import com.github.pagehelper.PageHelper;
import com.lehoon.tomato.global.UserContext;
import com.lehoon.tomato.model.Store;
import com.lehoon.tomato.model.User;
import com.lehoon.tomato.model.common.Result;
import com.lehoon.tomato.model.vo.StoreVo;
import com.lehoon.tomato.service.StoreService;
import com.lehoon.tomato.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wang
 * @since 2020-09-23
 */
@RestController
@RequestMapping("/auth/store/")
@Api(description = "店铺相关接口")
public class StoreController {

    @Resource
    private StoreService storeService;

    @Resource
    private UserService userService;

    @GetMapping
    @ApiOperation(value = "分页获取店铺列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="curPage",value="当前页",dataType="int", paramType = "query"),
            @ApiImplicitParam(name="pageSize",value="分页大小",dataType="int", paramType = "query")
    })
    public Result<List<StoreVo>> getStorePage(Integer curPage,Integer pageSize){
        Integer userId = UserContext.getUser().getId();
        Result<List<StoreVo>> result = new Result();
        User user = userService.getUserById(userId);
        PageHelper.startPage(curPage,pageSize);
        if(user.getSchoolId()==null||user.getBedroomId()==null){
            return result;
        }
        List<StoreVo> storeList = storeService.getStoreList(user.getSchoolId(),user.getBedroomId());
        return Result.successResult(storeList);
    }
}

